package com.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.sun.org.apache.bcel.internal.generic.NEW;
import com.tanhua.dubbo.api.db.SoulApi;
import com.tanhua.dubbo.api.mapper.SoulMapper;
import com.tanhua.model.db.Options;
import com.tanhua.model.db.Report;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @Description
 * @Author admin
 * @Create 2021/12/28 - 10:02
 * @Version
 */
@DubboService
public class SoulApiImpl implements SoulApi {

    @Autowired
    private SoulMapper soulMapper;


    /**
     * 根据用户和当前等级获取报告对象
     * @param userId
     * @param nowLevel
     * @return
     */
    @Override
    public Report findReport(Long userId, String nowLevel) {
        QueryWrapper<Report> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id",userId).eq("level",nowLevel);
        return soulMapper.selectOne(queryWrapper);
    }
    /**
     * 更新report表
     * @param report
     */
    @Override
    public void updateReport(Report report) {
        QueryWrapper<Report> queryWrapper = new QueryWrapper();
        queryWrapper.eq("user_id",report.getUserId());
        queryWrapper.eq("level",report.getLevel());
        int update = soulMapper.update(report, queryWrapper);
        System.out.println(update);
    }

    /**
     * 插入report表
     * @param report
     */
    @Override
    public void insertReport(Report report) {
        soulMapper.insert(report);
    }
}
